package kama;

import java.util.*;

public class Test0105 {
}

class Main0105_1{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int length1 = scanner.nextInt();
        int length2 = scanner.nextInt();
        boolean[] records = new boolean[length1];
        records[0] = true;
        ArrayList<List<Integer>> sides = new ArrayList<>();

        for (int i = 0; i < length1; i++) sides.add(new ArrayList<>());
        for (int i = 0; i < length2; i++)
            sides.get(scanner.nextInt()-1).add(scanner.nextInt());

        Queue<Integer> deque = new ArrayDeque<>();
        Queue<Integer> deque1 = new ArrayDeque<>();
        deque.offer(1);
        while (!deque.isEmpty()){
            while (!deque.isEmpty()){
                Integer now = deque.poll();
                for (Integer i : sides.get(now - 1)) {
                    if (!records[i-1]) deque1.offer(i);
                    records[i-1] = true;
                }
            }
            Queue<Integer> temp = deque1;
            deque1 = deque;
            deque = temp;
        }

        for (boolean record : records)
            if (!record){
                System.out.println(1);
                return;
            }
        System.out.println(1);
    }
}
